const crypto = require('crypto');
const randomString = require('random-string');

// 判断是否是PC
export function isPC(ua) {
  const Agents = [ 'Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod' ];
  let flag = true;
  for (let v = 0; v < Agents.length; v++) {
    if (ua.indexOf(Agents[v]) > 0) { flag = false; break; }
  }
  return flag;
}
// 生成随机数
export function createRandomString(options?: {length?: number, numeric?: boolean, letters?: boolean, special?: boolean, exclude?: string[]}) {
  return randomString(options);
}
// 生成MD5值
export function createMD5(string: string, salt?: string) {
  const md5 = crypto.createHash('md5');
  if (!salt) {
    return md5.update(string).digest('hex');
  }
  const saltPassword = string + ':' + salt;
  return md5.update(saltPassword).digest('hex');

}
